# coding=utf-8
# 编译日期：2022-08-05 10:58:41
# 版权所有：www.i-search.com.cn
import time
import pdb
from ubpa.ilog import ILog
from ubpa.base_img import *
import getopt
from sys import argv
import sys
import datetime
import os
import os 
import pandas as pd
import paramiko
import re
import shutil
import traceback
import ubpa.ibrowse as ibrowse
import ubpa.ichrome_firefox as ichrome_firefox
import ubpa.ikeyboard as ikeyboard
import ubpa.iocr as iocr
import ubpa.iwin as iwin

class Dserver:
     
    def __init__(self,**kwargs):
        self.__logger = ILog(__file__)
        self.path = set_img_res_path(__file__)
        self.robot_no = ''
        self.proc_no = ''
        self.job_no = ''
        self.input_arg = ''
        if('robot_no' in kwargs.keys()):
            self.robot_no = kwargs['robot_no']
        if('proc_no' in kwargs.keys()):
            self.proc_no = kwargs['proc_no']
        if('job_no' in kwargs.keys()):
            self.job_no = kwargs['job_no']
        if('input_arg' in kwargs.keys()):
            self.input_arg = kwargs['input_arg']
            self.input_arg = self.input_arg.replace("\\","/")
        self.driver=None
        self.imgPath=None
        self.configFile=None
        self.sftpDowndir=None
        self.templateUploadFile=None
        self.dom_text=None
        self.sftp_list=[]
        self.chromePath=r"C:\Program Files\Google\Chrome\Application\chrome.exe"
        self.PassWord=None
        self.UserName=None
        self.taskDir=r'D:\RPA\接口文档/'
        self.Movedir2=r'D:\RPA\temp\dfqc\Downloadfile/'
        self.organizeUrl=[]
        self.Arrpath2=r'D:\RPA\temp\dfqc\Do/'
        self.originalUrl=[]
        self.Arrpath1=r'D:\RPA\temp\ty\Do/'
        self.Movedir1=r'D:\RPA\temp\ty\Downloadfile/'
        self.Temppath=r"D:\RPA\temp\PO单通用数据结构.xlsx"
        self.Configdir=r"D:\RPA\temp/"
        self.Sftpdir='sftp://mysftp@47.118.52.110/upload/dev/'
        self.Arrpath=r'D:\RPA\temp\cyc\Do/'
        self.Movedir=r"D:\RPA\temp\cyc\Downloadfile/"
        self.Downdir=r'C:\Users\xxxx\Downloads/'
        self.configList=None
        self.Token=[]
        self.Interface=[]
        self.Datadic={'供应商':['C272—上汽变速器'],'出货地':['A2'],'状态':['已出货'],'到货指示时间起':['2021-06-30']}
        self.TemplateCode=None
        self.client=None
        self.userList=None
        self.sysCode=None
        self.callbackUrl="http://sit.sccp.mastr.top:61517/sccp-web-api-sit/openapi/rpa/callback"
        self.taskId=None
        self.robot_status=r'D:\RPA\接口文档\机器人状态.txt'
        self.Txtrob=r'D:\RPA\接口文档\接口数据.txt'
      
    def Login_ty(self):
        '''[Group]:上汽通用\n'''
        account='sagw123'
        password='TIzMTIzKiMIypTYWd3M='
        ocr_img=None
        # Try异常
        self.__logger.debug('Flow:Login_ty,StepNodeTag:0211335039842,Note:登录是否异常')
        try:
            # 序列
            self.__logger.debug('Flow:Login_ty,StepNodeTag:2021042912595111756,Note:通用物流序列')
            # For循环
            self.__logger.debug('Flow:Login_ty,StepNodeTag:0211010623715,Note:for循环10次')
            for item_0211010623715 in range(5):
                # Try异常
                self.__logger.debug('Flow:Login_ty,StepNodeTag:0211011700317,Note:打开网站是否异常')
                try:
                    # 代码块
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:1916015877687,Note:杀死进程')
                    import os
                    os.system("taskkill /im chrome.exe")
                    os.system("taskkill /im chrome.exe")
                    os.system("taskkill /im chrome.exe")
                    #打开浏览器
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:1916021366689,Note:打开浏览器')
                    time.sleep(2)
                    ibrowse.open_browser(browser_type='chrome',url=r'https://supplyone.ap1.covapp.io/#/login',path=self.chromePath)
                    # 最大化窗口
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:061028394201,Note:最大化')
                    iwin.do_win_maximize(win_title=r'欢迎使用 SupplyOnline II - Google Chrome',win_text=r'',waitfor=10)
                    # 热键输入
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:051057412612,Note:')
                    ikeyboard.key_send_cs(text='^R',waitfor=10)
                    # Break中断
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:0211014930121,Note:成功打开 中断')
                    break
                except Exception as e:
                    pass
                finally:
                    pass
            # 热键输入
            self.__logger.debug('Flow:Login_ty,StepNodeTag:1916032069092,Note:')
            time.sleep(2)
            ikeyboard.key_send_cs(text='#{UP}',waitfor=10)
            # For循环
            self.__logger.debug('Flow:Login_ty,StepNodeTag:2021042913014053169,Note:for循环5次')
            for ii in range(5):
                # 序列
                self.__logger.debug('Flow:Login_ty,StepNodeTag:2021042913014434572,Note:登录序列')
                # 设置文本
                self.__logger.debug('Flow:Login_ty,StepNodeTag:1916035511398,Note:输入tywl用户名')
                time.sleep(3)
                ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>form>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"用户名","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/login","xpath":"//*"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/login',text=self.UserName,waitfor=10)
                # 设置文本
                self.__logger.debug('Flow:Login_ty,StepNodeTag:19160603731104,Note:输入tywl密码')
                ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>form>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"密码","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"password","url":"https://supplyone.ap1.covapp.io/#/login","xpath":"//*"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/login',text=self.PassWord,waitfor=10)
                # Try异常
                self.__logger.debug('Flow:Login_ty,StepNodeTag:26172942819263,Note:异常优化')
                try:
                    # 元素截图
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:19160616120108,Note:元素截图 11')
                    time.sleep(1)
                    tvar19160616120108 = ichrome_firefox.capture_image_chrome(attrMap={"aastate":"enabled","css-selector":"body>div>div>div>div>div>div>form>div>div>span>img","isleaf":"1","parentid":"app","parenttag":"SPAN","readystate":"1","role":"element","selecteditems":"{  }","src":"https://supplyone.ap1.covapp.io/authorize/captcha?*","tag":"IMG","url":"*","xpath":"//*"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/login',waitfor=10)
                    #验证码
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:19160623899109,Note:验证码11')
                    tvar19160623899109 = iocr.vcode_recognize(image_path=tvar19160616120108,code_type=7000,apiKey='1aaaedb313da4618aa54f25890c4ad86',secretKey='dc0c34f670524386b675c5133d560247')
                    # 设置文本
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:19160817161121,Note:输入验证码11')
                    ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>form>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"验证码","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/login","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[2]/div[1]/div[1]/form[1]/div[3]/div[1]/div[1]/div[1]/div[1]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/login',text=tvar19160623899109,waitfor=10)
                except Exception as e:
                    # 元素截图
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:26172955788266,Note:元素截图22')
                    time.sleep(1)
                    tvar26172955788266 = ichrome_firefox.capture_image_chrome(attrMap={"aastate":"enabled","css-selector":"body>div>div>div>div>div>div>form>div>div>span>img","isleaf":"1","parentid":"app","parenttag":"SPAN","readystate":"1","role":"element","selecteditems":"{  }","src":"https://supplyone.ap1.covapp.io/authorize/captcha?*","tag":"IMG","url":"*","xpath":"//*"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/login',waitfor=10)
                    #验证码
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:26172955788268,Note:验证码22')
                    tvar26172955788268 = iocr.vcode_recognize(image_path=tvar26172955788266,code_type=7000,apiKey='1aaaedb313da4618aa54f25890c4ad86',secretKey='dc0c34f670524386b675c5133d560247')
                    # 设置文本
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:26172955788267,Note:输入验证码22')
                    ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>form>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"验证码","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/login","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[2]/div[1]/div[1]/form[1]/div[3]/div[1]/div[1]/div[1]/div[1]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/login',text=tvar26172955788268,waitfor=10)
                finally:
                    pass
                # 鼠标点击
                self.__logger.debug('Flow:Login_ty,StepNodeTag:19160844687124,Note:点击登录')
                time.sleep(1.5)
                ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"登录","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>form>div>div>button>span","isleaf":"1","parentid":"app","parenttag":"BUTTON","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/login","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[2]/div[1]/div[1]/form[1]/div[4]/div[1]/button[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/login',button=r'left',curson=r'center',times=1,run_mode=r'ctrl',waitfor=10)
                # Try异常
                self.__logger.debug('Flow:Login_ty,StepNodeTag:21174654348100,Note:判断是否登录成功')
                try:
                    # 获取文本
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:2117462263196,Note:点击首页')
                    tvar2117462263196 = ichrome_firefox.get_element_val_chrome(attrMap={"aaname":"首页","aastate":"enabled","css-selector":"body>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/homePage/getmenuInfo","xpath":"//*[@id=\"app\"]/div[1]/div[1]/div[3]/span[4]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/homePage/getmenuInfo',waitfor=10)
                    # IF-N分支
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:20210429130905987111,Note:')
                    if tvar2117462263196:
                        # Break中断
                        self.__logger.debug('Flow:Login_ty,StepNodeTag:20210429130706882106,Note:成功登录中断循环判断')
                        break
                    else:
                        pass
                except Exception as e:
                    # IF-N分支
                    self.__logger.debug('Flow:Login_ty,StepNodeTag:301322354256,Note:已 ii==4 ？')
                    if ii == 4:
                        # 子流程:flow7
                        self.__logger.debug('Flow:Login_ty,StepNodeTag:301322458918,Note:上汽通用登录失败')
                        (temptemp)=self.flow7(text="上汽通用登录失败")
                    else:
                        # 键盘输入
                        self.__logger.debug('Flow:Login_ty,StepNodeTag:19161230195133,Note:刷新')
                        time.sleep(0.5)
                        ikeyboard.key_send_cs(text='{F5}',waitfor=10)
                        time.sleep(3)
                finally:
                    pass
        except Exception as e:
            # 子流程:flow7
            self.__logger.debug('Flow:Login_ty,StepNodeTag:0211335972846,Note:上汽通用登录失败')
            (temptemp)=self.flow7(text="上汽通用登录失败")
        finally:
            pass
      
    def Parsing_Json(self):
        # Try异常
        self.__logger.debug('Flow:Parsing_Json,StepNodeTag:021241044682,Note:')
        try:
            # 代码块
            self.__logger.debug('Flow:Parsing_Json,StepNodeTag:021241044683,Note:')
            try:
                with open(self.Txtrob,'r',encoding='utf-8') as f:
                    jsondic = f.read().split('\n')[-1]
            except:
                with open(self.Txtrob,'r') as f:
                    jsondic = f.read().split('\n')[-1]    
            print(jsondic)    
            jsondic = eval(jsondic)
            print(jsondic)
            print(type(jsondic))
             
            #jsondic = {'TaskId': 22341, 'TemplateCode': 'W01004','Data': {'UserList': [{'username': '653811398', 'password': 'Sagw202101', 'ConfigList': []}]}}
            #jsondic = {'TaskId': 22341, 'TemplateCode': 'W01001', 'Data': {'UserList': [{'username': 'user1', 'password': 'pass1', 'config_list': [{'params1': 'v1', 'params2': 'v2'}, {'params1': 'v1', 'params2': 'v3'}]}, {'username': 'user2', 'password': 'pass2', 'config_list': [{'params1': 'v1', 'params2': 'v2'}, {'params1': 'v3', 'params2': 'v4'}]}]}}
            #self.Token = jsondic['token']
            self.TemplateCode = jsondic['templateCode']
            print('TemplateCode',self.TemplateCode)
            self.taskId = jsondic['taskId']
            print(self.taskId)
            self.callbackUrl = jsondic['callbackUrl']
            print(self.callbackUrl)
            self.userList = jsondic['data']['userList']
            print('这儿',self.userList)
            # self.configList = jsondic['data']['userList']
            try:
                self.sysCode = self.Data['sysCode']
                self.client = self.Data['client']
            except:
                pass    
            df_initialize3 = pd.read_excel(r'D:\RPA\configFile\configFile_saas.xlsx',sheet_name = 'templateCode')
            for idx, row in df_initialize3.iterrows():
                if row['template_code'] == self.TemplateCode:
                    self.templateUploadFile = row['上传数据模板']
            
        except Exception as e:
            # 子流程:flow7
            self.__logger.debug('Flow:Parsing_Json,StepNodeTag:0211435576567,Note:')
            (temptemp)=self.flow7(text="Json解析失败！！！！")
        finally:
            pass
      
    def flow2(self):
        '''[Group]:上汽通用\n'''
        code=0
        kaccount=0
        account=1
        templ=[]
        name1=None
        index=1
        name=None
        # 序列
        self.__logger.debug('Flow:flow2,StepNodeTag:20210429130957190119,Note:ty_wl_学列')
        # 鼠标点击
        self.__logger.debug('Flow:flow2,StepNodeTag:19161304999135,Note:订单管理')
        time.sleep(2)
        ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"订单管理","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/homePage/getmenuInfo","xpath":"//*[@id=\"app\"]/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[15]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/homePage/getmenuInfo',button=r'left',curson=r'center',offsetY=-80,times=1,run_mode=r'unctrl',waitfor=10)
        # 鼠标点击
        self.__logger.debug('Flow:flow2,StepNodeTag:19161345233138,Note:零件及订单')
        time.sleep(2)
        ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"零件级订单","aastate":"enabled","css-selector":"body>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[1]/span[2]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
        # 鼠标点击
        self.__logger.debug('Flow:flow2,StepNodeTag:19161418576140,Note:高级查询')
        time.sleep(1.5)
        ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"高级查询","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>button>span","isleaf":"1","parentid":"app","parenttag":"BUTTON","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[1]/div[1]/button[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
        # Try异常
        self.__logger.debug('Flow:flow2,StepNodeTag:3021363198552,Note:')
        try:
            # 鼠标点击
            self.__logger.debug('Flow:flow2,StepNodeTag:3021131691846,Note:点击工厂 框11')
            time.sleep(1.5)
            ichrome_firefox.do_click_pos_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[1]/div[1]/div[1]/div[1]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
        except Exception as e:
            # 鼠标点击
            self.__logger.debug('Flow:flow2,StepNodeTag:3021355117350,Note:点击工厂 框22')
            time.sleep(1.5)
            ichrome_firefox.do_click_pos_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[1]/div[1]/div[1]/div[1]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
        finally:
            pass
        # 获取文本
        self.__logger.debug('Flow:flow2,StepNodeTag:19161524675143,Note:获取工厂')
        name = ichrome_firefox.get_element_val_chrome(attrMap={"aaname":"工厂:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/*","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[1]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/*',waitfor=10)
        # 代码块
        self.__logger.debug('Flow:flow2,StepNodeTag:19161630516154,Note:name = name.replace()')
        name = name.replace(':','')
        # IF-N分支
        self.__logger.debug('Flow:flow2,StepNodeTag:01150905116188,Note:name in self.Datadic')
        if name in self.Datadic:
            # While循环
            self.__logger.debug('Flow:flow2,StepNodeTag:20210429131603134130,Note:while循环')
            while 1:
                # Try异常
                self.__logger.debug('Flow:flow2,StepNodeTag:20210429132508081158,Note:TRy异常')
                try:
                    # 获取文本
                    self.__logger.debug('Flow:flow2,StepNodeTag:19161731808158,Note:获取工厂')
                    name1 = ichrome_firefox.get_element_val_chrome(attrMap={"aaname":"*","aastate":"enabled","css-selector":"body>div>div>div>ul>li>span","isleaf":"1","parenttag":"LI","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"/html/body/div[2]/div[1]/div[1]/ul[1]/li[{}]/span[1]".format(index)},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/*',waitfor=3)
                    # IF-N分支
                    self.__logger.debug('Flow:flow2,StepNodeTag:01151500264201,Note:name1 in self.Datadic[name]')
                    if name1 in self.Datadic[name]:
                        # 鼠标点击
                        self.__logger.debug('Flow:flow2,StepNodeTag:01151055711194,Note:点击 工厂')
                        ichrome_firefox.do_click_pos_chrome(attrMap={"aastate":"enabled","css-selector":"body>div>div>div>ul>li","isleaf":"0","parenttag":"UL","readystate":"1","role":"element","selecteditems":"{  }","tag":"LI","url":"https://supplyone.ap1.covapp.io/*","xpath":"/html/body/div[2]/div[1]/div[1]/ul[1]/li[{}]".format(index)},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/*',button=r'left',curson=r'center',times=1,run_mode=r'ctrl',waitfor=10)
                    else:
                        pass
                    # 代码块
                    self.__logger.debug('Flow:flow2,StepNodeTag:01152350029247,Note:index +=1')
                    index +=1
                except Exception as e:
                    # Break中断
                    self.__logger.debug('Flow:flow2,StepNodeTag:19161851527166,Note:异常时 中断')
                    break
                finally:
                    pass
            # 鼠标点击
            self.__logger.debug('Flow:flow2,StepNodeTag:19162020138168,Note:点击工厂')
            time.sleep(1.5)
            ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"工厂:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[1]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
            # 代码块
            self.__logger.debug('Flow:flow2,StepNodeTag:19162041287170,Note:index = 1')
            index = 1
        else:
            pass
        # 获取文本
        self.__logger.debug('Flow:flow2,StepNodeTag:19162107233172,Note:获取订单状态')
        time.sleep(1.5)
        name = ichrome_firefox.get_element_val_chrome(attrMap={"aaname":"订单状态:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[5]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',waitfor=10)
        # 鼠标点击
        self.__logger.debug('Flow:flow2,StepNodeTag:271725173722,Note:点击订单状态')
        time.sleep(3)
        ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"订单状态:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/*","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[5]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
        # 代码块
        self.__logger.debug('Flow:flow2,StepNodeTag:19162124659177,Note:name = name.replace()')
        name = name.replace(':','')
        # IF-N分支
        self.__logger.debug('Flow:flow2,StepNodeTag:01151714410206,Note:name in self.Datadic')
        if name in self.Datadic:
            # While循环
            self.__logger.debug('Flow:flow2,StepNodeTag:202105071749496551112,Note:while循环')
            while 1:
                # 鼠标点击
                self.__logger.debug('Flow:flow2,StepNodeTag:19162224647180,Note:点击 选择框')
                time.sleep(1.5)
                ichrome_firefox.do_click_pos_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"请选择","readonly":"readonly","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[5]/div[1]/div[1]/div[1]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
                # For循环
                self.__logger.debug('Flow:flow2,StepNodeTag:19162311924182,Note:for循环')
                for item_19162311924182 in range(account):
                    # 键盘输入
                    self.__logger.debug('Flow:flow2,StepNodeTag:19162343176184,Note:模拟案件DOWN')
                    time.sleep(0.5)
                    ikeyboard.key_send_cs(text='{DOWN}',waitfor=10)
                # 键盘输入
                self.__logger.debug('Flow:flow2,StepNodeTag:19162407682187,Note:模拟按键 enter')
                time.sleep(0.5)
                ikeyboard.key_send_cs(text='{ENTER}',waitfor=10)
                # 获取文本
                self.__logger.debug('Flow:flow2,StepNodeTag:19164432311248,Note:获取文本呢')
                time.sleep(1)
                name1 = ichrome_firefox.get_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"请选择","*":"*","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/*","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[5]/div[1]/div[1]/div[1]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/*',waitfor=10)
                # IF-N分支
                self.__logger.debug('Flow:flow2,StepNodeTag:01151859828216,Note:name1 in self.Datadic[name]')
                if name1 in self.Datadic[name]:
                    # Break中断
                    self.__logger.debug('Flow:flow2,StepNodeTag:01151916326218,Note:name1 in self.Datadic[name] 中断')
                    break
                else:
                    pass
                # IF-N分支
                self.__logger.debug('Flow:flow2,StepNodeTag:19162501729194,Note:name1 in templ')
                if name1 in templ:
                    # Break中断
                    self.__logger.debug('Flow:flow2,StepNodeTag:19162515998196,Note:name1 in templ 中断')
                    break
                else:
                    pass
                # 代码块
                self.__logger.debug('Flow:flow2,StepNodeTag:19162520493198,Note:')
                index +=1
                if account == 1:
                    account +=2
                else:    
                   account +=1
                templ.append(name1)
                
            # 鼠标点击
            self.__logger.debug('Flow:flow2,StepNodeTag:19165823690261,Note:点击所有')
            time.sleep(1.5)
            ichrome_firefox.do_click_pos_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"请选择","readonly":"readonly","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[5]/div[2]/div[1]/div[1]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
            # 代码块
            self.__logger.debug('Flow:flow2,StepNodeTag:19165812671260,Note:index = 1')
            index = 1
        else:
            pass
        # 获取文本
        self.__logger.debug('Flow:flow2,StepNodeTag:19162557632199,Note:订单子类型')
        time.sleep(1.5)
        name = ichrome_firefox.get_element_val_chrome(attrMap={"aaname":"订单子类型:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/*","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[5]/div[2]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/*',waitfor=10)
        # 代码块
        self.__logger.debug('Flow:flow2,StepNodeTag:19162608905204,Note:name = name.replace()')
        name = name.replace(':','')
        # IF-N分支
        self.__logger.debug('Flow:flow2,StepNodeTag:01151945730220,Note:name in self.Datadic')
        if name in self.Datadic:
            # While循环
            self.__logger.debug('Flow:flow2,StepNodeTag:19162642878207,Note:while循环')
            while 1:
                # Try异常
                self.__logger.debug('Flow:flow2,StepNodeTag:19162652485209,Note:Try异常')
                try:
                    # 获取文本
                    self.__logger.debug('Flow:flow2,StepNodeTag:19162656695211,Note:获取文本讷')
                    name1 = ichrome_firefox.get_element_val_chrome(attrMap={"aastate":"enabled","css-selector":"body>div>div>div>ul>li","isleaf":"0","parenttag":"UL","readystate":"1","role":"element","selecteditems":"{  }","tag":"LI","url":"https://supplyone.ap1.covapp.io/*","xpath":"/html/body/div[4]/div[1]/div[1]/ul[1]/li[{}]".format(index)},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/*',waitfor=5)
                    # IF-N分支
                    self.__logger.debug('Flow:flow2,StepNodeTag:01152220244235,Note:name1 in self.Datadic[name]')
                    if name1 in self.Datadic[name]:
                        # 鼠标点击
                        self.__logger.debug('Flow:flow2,StepNodeTag:01152049286231,Note:点击 bT-自建')
                        ichrome_firefox.do_click_pos_chrome(attrMap={"aastate":"enabled","css-selector":"body>div>div>div>ul>li","isleaf":"0","parenttag":"UL","readystate":"1","role":"element","selecteditems":"{  }","tag":"LI","url":"https://supplyone.ap1.covapp.io/*","xpath":"/html/body/div[4]/div[1]/div[1]/ul[1]/li[{}]".format(index)},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/*',button=r'left',curson=r'center',times=1,run_mode=r'ctrl',waitfor=10)
                        # Break中断
                        self.__logger.debug('Flow:flow2,StepNodeTag:01152229853242,Note:name1 in self.Datadic[name] 中断')
                        break
                    else:
                        pass
                    # 代码块
                    self.__logger.debug('Flow:flow2,StepNodeTag:19162748503218,Note:index +=1')
                    index +=1
                except Exception as e:
                    # Break中断
                    self.__logger.debug('Flow:flow2,StepNodeTag:19162738718216,Note:异常时中断')
                    break
                finally:
                    pass
        else:
            pass
        # 子流程:flow5
        self.__logger.debug('Flow:flow2,StepNodeTag:16185444056183,Note:进入flow5流程')
        (temptemp)=self.flow5()
        # 鼠标点击
        self.__logger.debug('Flow:flow2,StepNodeTag:0214055155751,Note:实时获取订单')
        time.sleep(2)
        ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"*","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/*","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[3]/span[2]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/*',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
        # 鼠标点击
        self.__logger.debug('Flow:flow2,StepNodeTag:0214064919853,Note:查询')
        time.sleep(5)
        ichrome_firefox.do_click_pos_chrome(attrMap={"aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[1]/div[1]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'ctrl',waitfor=10)
        time.sleep(5)
        # 鼠标点击
        self.__logger.debug('Flow:flow2,StepNodeTag:231745122101,Note:零件级订单下载')
        ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"零件级订单下载","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[3]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
        time.sleep(8)
        # 代码块
        self.__logger.debug('Flow:flow2,StepNodeTag:211717084044,Note:下载的excel文件俄式不可更改，例：sheet名称、表头')
        import os 
        import pandas as pd
        import datetime
        import shutil
        #  C:\Users\yiye_yangliupu\Downloads\零件级订单汇总.xlsx
        now = str(datetime.datetime.now()).replace(' ','-').replace(':','_',5)
        print('时间now',now)
        if not os.path.exists(self.Movedir1 + now):
            os.mkdir(self.Movedir1 + now)
        if not os.path.exists(self.Arrpath1 + now):
            os.mkdir(self.Arrpath1 + now)
        arr_path = self.Arrpath1 + now   # 整理后的文件，上传sftp的文件夹
        sc_path = self.Movedir1 + now    # 下载的源文件，上传sftp文件夹
        #filename = 'fc6bd8d1-fc93-42f4-8c80-cf1d35f182dc.xlsx'
        redir = self.Movedir1 + now + '/' + now + 'ty.xlsx'    # 待读取excel文件即下载下来的wexcel
        print('读取的文件路劲',redir)
        print('读取的文件路劲',redir)
        print('读取的文件路劲',redir)
        for t in range(30):
            if not os.path.exists(self.Downdir + '零件级订单汇总.xlsx'):
                time.sleep(8)
                print('?????????')
                print(self.Downdir + '零件级订单汇总.xlsx')
            else: 
                shutil.move(self.Downdir+'零件级订单汇总.xlsx',redir)
                print('yidong')
                #self.DataUrl[0].append(redir)
                break  
        time.sleep(5)        
        df = pd.read_excel(redir,sheet_name = 'sheet1')
        print(df)
        allrow = df.shape[0]
        print('总行数为：',allrow)
        print('总行数为：',type(allrow))
        now1 = now
        # IF-N分支
        self.__logger.debug('Flow:flow2,StepNodeTag:211717084046,Note:allrow == 0')
        if allrow == 0:
            pass
        else:
            # 代码块
            self.__logger.debug('Flow:flow2,StepNodeTag:211717084047,Note:处理数据')
            import pandas as pd
            from openpyxl import load_workbook
            kvalu = ''
            kaccount = 0
            wrdir = self.Arrpath1 + now + '/' + now + 'ty.xlsx'
            shutil.copyfile(self.Temppath,wrdir)
            dlist1 = []
            vnone = ['虚拟零件号','发货单号','发货单行号','车型','供应商编号']
            configdir = self.Configdir + 'config_ty.TXT'
            now = str(datetime.datetime.now()).split('.')[0]
            try:
                with open(configdir,'r',encoding='utf-8') as f:
                    condic = f.read()
            except:
                with open(configdir,'rb') as f:
                    condic = f.read()    
            condic = eval(condic)
            wb = load_workbook(wrdir)
            ws = wb['Sheet1']
            df = pd.read_excel(wrdir,sheet_name='Sheet1',header=None)
            headers = df.loc[0].values.tolist()
            df1 = pd.read_excel(redir,sheet_name='sheet1',dtype=str)
            # df1 = df1.fillna('##')
            #a = df1.loc[2].values.tolist()
            allrow = df1.shape[0]
            for row in range(allrow):
                dlist = []
                for index,col in enumerate(headers):
                    if col in condic:
                        if col == '客户工厂':
                            kvalu = df1[condic[col]]
                            kvalu = kvalu.values.tolist()[row]
                            kvalu = str(kvalu)
                        val = df1[condic[col]]
                        dlist.append(val.values.tolist()[row])
                    elif col == '订单行号':
                        dlist.append(1)
                    elif col == '单据类型':
                        dlist.append(10)
                    elif col == '写入时间':
                        dlist.append(now)
                    elif col == '网址简称':
                        dlist.append(self.TemplateCode)
                    elif col in vnone:
                        dlist.append(' ')
                kaccount = 1  
                code = 0    
                for index1,i in enumerate(self.Interface):
                    for k,v in i.items():
                        if kvalu == v:
                            dlist.insert(3,i['customerCode'])
                            #dlist.remove(dlist[4])
                            dlist.insert(15,' ')
                            #dlist.remove(dlist[16])
                            dlist.insert(16,i['plantId'])
                            #dlist.remove(dlist[17])
                            dlist.insert(17,i['shippingBay'])
                            #dlist.remove(dlist[18])
                            dlist.insert(18,i['salesOrganization'])
                            #dlist.remove(dlist[19])
                            dlist.insert(19,i['distributionChannel'])
                            #dlist.remove(dlist[20])
                            dlist.insert(20,i['productGroup'])
                            #dlist.remove(dlist[21])
                            dlist.insert(21,i['shippingPoint'])
                            #dlist.remove(dlist[22])
                            code = 1
                            break
                    if code == 1:
                        break
                    if kaccount == len(self.Interface):
                        print('主数据未能匹配！！！！！')
                        print('主数据未能匹配！！！！！')
                        print('主数据未能匹配！！！！！')
                        dlist.insert(3,' ')
                        #dlist.remove(dlist[4])
                        dlist.insert(15,' ')
                        dlist.insert(16,' ')
                        dlist.insert(17,' ')
                        dlist.insert(18,' ')
                        dlist.insert(19,' ')
                        dlist.insert(20,' ')
                        dlist.insert(21,' ') 
                        #kaccount = 0
                        continue
                    kaccount +=1    
                dlist1.append(dlist)
                # print('////////////////////////////////////////////////////////////////////////////////////////////////////////////')
            # print(dlist1)
            aaa = []
            for ii in dlist1:
                bbb=[' ' if i =='nan' or i == None else i for i in ii]
                aaa.append(bbb)
            for i in aaa:
                ws.append(i)
            wb.save(wrdir)
            
            # 代码块
            self.__logger.debug('Flow:flow2,StepNodeTag:2117170840410,Note:通过IP, 用户名，密码，超时时间初始化一个远程Linux主机')
            # coding: utf-8
            import paramiko
            import re
            import os
            from time import sleep
            class Linux(object):
                # 通过IP, 用户名，密码，超时时间初始化一个远程Linux主机
                def __init__(self, ip, username, password, timeout=3000):
                    self.ip = ip
                    self.username = username
                    self.password = password
                    self.timeout = timeout
                    # transport和chanel
                    self.t = ''
                    self.chan = paramiko.Transport((ip, 22))
                    # 链接失败的重试次数
                    self.try_times = 3
                # 调用该方法连接远程主机
                def connect(self):
                    while True:
                        # 连接过程中可能会抛出异常，比如网络不通、链接超时
                        try:
                            self.t = paramiko.Transport(sock=(self.ip, 22))
                            self.t.connect(username=self.username, password=self.password)
                            self.chan = self.t.open_session()
                            self.chan.settimeout(self.timeout)
                            self.chan.get_pty()
                            self.chan.invoke_shell()
                            # 如果没有抛出异常说明连接成功，直接返回
                            print(u'连接%s成功' % self.ip)
                            # 接收到的网络数据解码为str
                            print(self.chan.recv(65535).decode('utf-8'))
                            return
                        # 这里不对可能的异常如socket.error, socket.timeout细化，直接一网打尽
                        except Exception as e1:
                            if self.try_times != 0:
                                print(u'连接%s失败，进行重试' % self.ip)
                                self.try_times -= 1
                            else:
                                print(u'重试3次失败，结束程序')
                                exit(1)
                # 断开连接
                def close(self):
                    self.chan.close()
                    self.t.close()
                # ------获取本地指定目录及其子目录下的所有文件------
                def __get_all_files_in_local_dir(self, local_dir):
                    # 保存所有文件的列表
                    all_files = list()
                    # 获取当前指定目录下的所有目录及文件，包含属性值
                    files = os.listdir(local_dir)
                    for x in files:
                        # local_dir目录中每一个文件或目录的完整路径
                        filename = os.path.join(local_dir, x)
                        # 如果是目录，则递归处理该目录
                        if os.path.isdir(x):
                            all_files.extend(self.__get_all_files_in_local_dir(filename))
                        else:
                            all_files.append(filename)
                    return all_files
                def sftp_put_dir(self, local_dir, remote_dir):
                    t = paramiko.Transport(sock=(self.ip, 22))
                    t.connect(username=self.username, password=self.password)
                    sftp = paramiko.SFTPClient.from_transport(t)
                    # 去掉路径字符穿最后的字符'/'，如果有的话
                    if remote_dir[-1] == '/':
                        remote_dir = remote_dir[0:-1]
                    # 获取本地指定目录及其子目录下的所有文件
                    all_files = self.__get_all_files_in_local_dir(local_dir)
                    print('待上传文件夹下所有文件',all_files)
                    # 依次put每一个文件
                    for x in all_files:
                        filename = os.path.split(x)[-1]
                        print('filename::',filename)
                        remote_filename = remote_dir + '/' + filename
                        print(remote_filename)
                        print(u'Put文件%s传输到%s中...' % (filename, self.ip))
                        print(remote_filename)
                        sftp.put(x, remote_filename)
            if __name__ == '__main__':
                remote_path = self.sftp_list[0][1] + "/organize/"
                local_path = arr_path
                hostArray = self.sftp_list
                for x in hostArray:
                    print(x)
                    host = Linux(x[0], x[2], x[3])
                    host.sftp_put_dir(local_path, remote_path)
                    now = str(datetime.datetime.now()).replace(' ','-').replace(':','_',5)
                    
                    self.organizeUrl.append(remote_path + '/' + now1 + 'ty.xlsx')
                    # host.close()
            # 热键输入
            self.__logger.debug('Flow:flow2,StepNodeTag:3021470664261,Note:去掉下载框')
            time.sleep(3)
            ikeyboard.key_send_cs(text='!w',waitfor=10)
        # 代码块
        self.__logger.debug('Flow:flow2,StepNodeTag:211717084049,Note:通过IP, 用户名，密码，超时时间初始化一个远程Linux主机')
        # coding: utf-8
        import paramiko
        import re
        import os
        from time import sleep
        class Linux(object):
            # 通过IP, 用户名，密码，超时时间初始化一个远程Linux主机
            def __init__(self, ip, username, password, timeout=3000):
                self.ip = ip
                self.username = username
                self.password = password
                self.timeout = timeout
                # transport和chanel
                self.t = ''
                self.chan = paramiko.Transport((ip, 22))
                # 链接失败的重试次数
                self.try_times = 3
            # 调用该方法连接远程主机
            def connect(self):
                while True:
                    # 连接过程中可能会抛出异常，比如网络不通、链接超时
                    try:
                        self.t = paramiko.Transport(sock=(self.ip, 22))
                        self.t.connect(username=self.username, password=self.password)
                        self.chan = self.t.open_session()
                        self.chan.settimeout(self.timeout)
                        self.chan.get_pty()
                        self.chan.invoke_shell()
                        # 如果没有抛出异常说明连接成功，直接返回
                        print(u'连接%s成功' % self.ip)
                        # 接收到的网络数据解码为str
                        print(self.chan.recv(65535).decode('utf-8'))
                        return
                    # 这里不对可能的异常如socket.error, socket.timeout细化，直接一网打尽
                    except Exception as e1:
                        if self.try_times != 0:
                            print(u'连接%s失败，进行重试' % self.ip)
                            self.try_times -= 1
                        else:
                            print(u'重试3次失败，结束程序')
                            exit(1)
            # 断开连接
            def close(self):
                self.chan.close()
                self.t.close()
            # ------获取本地指定目录及其子目录下的所有文件------
            def __get_all_files_in_local_dir(self, local_dir):
                # 保存所有文件的列表
                all_files = list()
                # 获取当前指定目录下的所有目录及文件，包含属性值
                files = os.listdir(local_dir)
                for x in files:
                    # local_dir目录中每一个文件或目录的完整路径
                    filename = os.path.join(local_dir, x)
                    # 如果是目录，则递归处理该目录
                    if os.path.isdir(x):
                        all_files.extend(self.__get_all_files_in_local_dir(filename))
                    else:
                        all_files.append(filename)
                return all_files
            def sftp_put_dir(self, local_dir, remote_dir):
                t = paramiko.Transport(sock=(self.ip, 22))
                t.connect(username=self.username, password=self.password)
                sftp = paramiko.SFTPClient.from_transport(t)
                # 去掉路径字符穿最后的字符'/'，如果有的话
                if remote_dir[-1] == '/':
                    remote_dir = remote_dir[0:-1]
                # 获取本地指定目录及其子目录下的所有文件
                all_files = self.__get_all_files_in_local_dir(local_dir)
                print('待上传文件夹下所有文件',all_files) #检测是否登陆成功
                # 依次put每一个文件
                for x in all_files:
                    filename = os.path.split(x)[-1]
                    print('filename::',filename)
                    remote_filename = remote_dir + '/' + filename
                    print(remote_filename)
                    print(u'Put文件%s传输到%s中...' % (filename, self.ip))
                    print(remote_filename)
                    sftp.put(x, remote_filename)
        if __name__ == '__main__':
            remote_path = self.sftp_list[0][1] + "/original/"
            local_path = sc_path
            hostArray = self.sftp_list
            for x in hostArray:
                print(x)
                host = Linux(x[0], x[2], x[3])
                host.sftp_put_dir(local_path, remote_path)
                now = str(datetime.datetime.now()).replace(' ','-').replace(':','_',5)
                self.originalUrl.append(remote_path + '/' + now1 + 'ty.xlsx')
                # host.close()
        # Try异常
        self.__logger.debug('Flow:flow2,StepNodeTag:281103588685,Note:TRy异常')
        try:
            pass
        except Exception as e:
            # 热键输入
            self.__logger.debug('Flow:flow2,StepNodeTag:140956305282,Note:去掉下载框')
            time.sleep(3)
            ikeyboard.key_send_cs(text='!w',waitfor=10)
        finally:
            pass
        # 鼠标点击
        self.__logger.debug('Flow:flow2,StepNodeTag:01153018604138,Note:点击首页')
        time.sleep(2)
        ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"首页","aastate":"enabled","css-selector":"body>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/*","xpath":"//*[@id=\"app\"]/div[1]/div[2]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/*',button=r'left',curson=r'center',times=1,run_mode=r'ctrl',waitfor=10)
      
    def flow5(self):
        '''[Group]:上汽通用\n'''
        # 序列
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379128,Note:开始flow5x序列')
        # 获取文本
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379129,Note:订单创建时间')
        time.sleep(1.5)
        name = ichrome_firefox.get_element_val_chrome(attrMap={"aaname":"订单创建时间:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/*","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/*',waitfor=10)
        # 代码块
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379162,Note:')
        name = name.replace(':','',2)
        # 鼠标点击
        self.__logger.debug('Flow:flow5,StepNodeTag:3019334681311,Note:去掉开始 订单创建时间')
        time.sleep(3)
        ichrome_firefox.do_click_pos_chrome(attrMap={"aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>div>span>span>i","isleaf":"1","parentid":"app","parenttag":"SPAN","readystate":"1","role":"element","selecteditems":"{  }","tag":"I","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/div[1]/span[2]/span[1]/i[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',offsetX=-12,times=2,run_mode=r'unctrl',waitfor=10)
        # 鼠标点击
        self.__logger.debug('Flow:flow5,StepNodeTag:3019423840728,Note:去掉开始 订单创建时间')
        time.sleep(1)
        ichrome_firefox.do_click_pos_chrome(attrMap={"aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>div>span>span>i","isleaf":"1","parentid":"app","parenttag":"SPAN","readystate":"1","role":"element","selecteditems":"{  }","tag":"I","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/div[1]/span[2]/span[1]/i[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',offsetX=-12,times=1,run_mode=r'unctrl',waitfor=10)
        # 鼠标点击
        self.__logger.debug('Flow:flow5,StepNodeTag:3019334681312,Note:去掉结束 订单创建时间')
        time.sleep(3)
        ichrome_firefox.do_click_pos_chrome(attrMap={"aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>div>span>span>i","isleaf":"1","parentid":"app","parenttag":"SPAN","readystate":"1","role":"element","selecteditems":"{  }","tag":"I","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/div[2]/span[2]/span[1]/i[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',offsetX=-12,times=2,run_mode=r'unctrl',waitfor=10)
        # IF-N分支
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379133,Note:')
        if name in self.Datadic:
            # For循环
            self.__logger.debug('Flow:flow5,StepNodeTag:1618521379169,Note:')
            for item_1618521379169 in range(2):
                # 设置文本
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379132,Note:')
                time.sleep(0.5)
                ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"开始日期","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/*","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/div[1]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/*',text=self.Datadic[name][0],waitfor=10)
                # 鼠标点击
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379170,Note:')
                time.sleep(1)
                ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"订单创建时间:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
                # 设置文本
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379131,Note:')
                time.sleep(0.5)
                ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"结束日期","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/div[2]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',text=self.Datadic[name][1],waitfor=10)
                # 鼠标点击
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379130,Note:')
                time.sleep(1)
                ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"订单创建时间:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
        else:
            pass
        # 获取文本
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379140,Note:计划到达时间')
        time.sleep(1.5)
        name = ichrome_firefox.get_element_val_chrome(attrMap={"aaname":"计划到达时间:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[2]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',waitfor=10)
        # 代码块
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379163,Note:')
        name = name.replace(':','',2)
        # IF-N分支
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379136,Note:')
        if name in self.Datadic:
            # For循环
            self.__logger.debug('Flow:flow5,StepNodeTag:1618521379171,Note:')
            for item_1618521379171 in range(2):
                # 设置文本
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379137,Note:')
                time.sleep(0.5)
                ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"开始日期","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[2]/div[1]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',text=self.Datadic[name][0],waitfor=10)
                # 鼠标点击
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379172,Note:')
                time.sleep(1)
                ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"订单创建时间:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
                # 设置文本
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379138,Note:')
                time.sleep(0.5)
                ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"结束日期","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[2]/div[2]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',text=self.Datadic[name][1],waitfor=10)
                # 鼠标点击
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379139,Note:')
                time.sleep(1)
                ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"订单创建时间:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
        else:
            pass
        # 获取文本
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379141,Note:实际到达时间从')
        time.sleep(1.5)
        name = ichrome_firefox.get_element_val_chrome(attrMap={"aaname":"实际到达时间(从):","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[3]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',waitfor=10)
        # 代码块
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379164,Note:')
        name = name.replace(':','',2)
        name = name.replace('(从)','',2)
        # IF-N分支
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379145,Note:')
        if name in self.Datadic:
            # For循环
            self.__logger.debug('Flow:flow5,StepNodeTag:1618521379173,Note:')
            for item_1618521379173 in range(2):
                # 设置文本
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379144,Note:')
                time.sleep(0.5)
                ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"选择日期","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[3]/div[1]/div[1]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',text=self.Datadic[name][0],waitfor=10)
                # 鼠标点击
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379174,Note:')
                time.sleep(1)
                ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"订单创建时间:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
                # 设置文本
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379143,Note:')
                time.sleep(0.5)
                ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"选择日期","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[3]/div[1]/div[2]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',text=self.Datadic[name][1],waitfor=10)
                # 鼠标点击
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379142,Note:')
                time.sleep(1)
                ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"订单创建时间:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
        else:
            pass
        # 获取文本
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379152,Note:计划提货时间从')
        time.sleep(1.5)
        name = ichrome_firefox.get_element_val_chrome(attrMap={"aaname":"计划提货时间(从):","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[3]/div[2]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',waitfor=10)
        # 代码块
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379165,Note:')
        name = name.replace(':','',2)
        name = name.replace('(从)','',2)
        # IF-N分支
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379148,Note:')
        if name in self.Datadic:
            # For循环
            self.__logger.debug('Flow:flow5,StepNodeTag:1618521379175,Note:')
            for item_1618521379175 in range(2):
                # 设置文本
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379149,Note:')
                time.sleep(0.5)
                ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"选择日期","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[3]/div[2]/div[1]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',text=self.Datadic[name][0],waitfor=10)
                # 鼠标点击
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379176,Note:')
                time.sleep(1)
                ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"订单创建时间:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
                # 设置文本
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379150,Note:')
                time.sleep(0.5)
                ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"选择日期","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[3]/div[2]/div[2]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',text=self.Datadic[name][1],waitfor=10)
                # 鼠标点击
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379151,Note:')
                time.sleep(1)
                ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"订单创建时间:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
        else:
            pass
        # 获取文本
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379155,Note:dock名称')
        time.sleep(1.5)
        name = ichrome_firefox.get_element_val_chrome(attrMap={"aaname":"dock名称:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[4]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',waitfor=10)
        # 代码块
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379166,Note:')
        name = name.replace(':','',2)
        # IF-N分支
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379154,Note:')
        if name in self.Datadic:
            # 设置文本
            self.__logger.debug('Flow:flow5,StepNodeTag:1618521379168,Note:')
            time.sleep(0.5)
            ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>textarea","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"请输入dock名称","readystate":"1","role":"element","selecteditems":"{  }","tag":"TEXTAREA","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[4]/div[1]/div[1]/textarea[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',text=self.Datadic[name][0],waitfor=10)
        else:
            pass
        # 获取文本
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379156,Note:最后处理时间')
        time.sleep(1.5)
        name = ichrome_firefox.get_element_val_chrome(attrMap={"aaname":"最后处理时间(从):","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[4]/div[2]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',waitfor=10)
        # 代码块
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379167,Note:')
        name = name.replace(':','',2)
        name = name.replace('(从)','',2)
        # IF-N分支
        self.__logger.debug('Flow:flow5,StepNodeTag:1618521379160,Note:')
        if name in self.Datadic:
            # For循环
            self.__logger.debug('Flow:flow5,StepNodeTag:1618521379177,Note:')
            for item_1618521379177 in range(2):
                # 设置文本
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379159,Note:')
                time.sleep(0.5)
                ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"选择日期","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[4]/div[2]/div[1]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',text=self.Datadic[name][0],waitfor=10)
                # 鼠标点击
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379178,Note:')
                time.sleep(1)
                ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"订单创建时间:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
                # 设置文本
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379158,Note:')
                time.sleep(0.5)
                ichrome_firefox.set_element_val_chrome(attrMap={"aastate":"enabled","autocomplete":"off","css-selector":"body>div>div>div>div>div>div>div>div>div>input","isleaf":"1","parentid":"app","parenttag":"DIV","placeholder":"选择日期","readystate":"1","role":"element","selecteditems":"{  }","tag":"INPUT","type":"text","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[4]/div[2]/div[2]/input[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',text=self.Datadic[name][1],waitfor=10)
                # 鼠标点击
                self.__logger.debug('Flow:flow5,StepNodeTag:1618521379157,Note:')
                time.sleep(1)
                ichrome_firefox.do_click_pos_chrome(attrMap={"aaname":"订单创建时间:","aastate":"enabled","css-selector":"body>div>div>div>div>div>div>div>div>span","isleaf":"1","parentid":"app","parenttag":"DIV","readystate":"1","role":"element","selecteditems":"{  }","tag":"SPAN","url":"https://supplyone.ap1.covapp.io/#/ground/orderManagement","xpath":"//*[@id=\"app\"]/div[1]/div[3]/div[1]/div[3]/div[2]/div[2]/div[1]/span[1]"},index=0,title=r'欢迎使用 SupplyOnline II',url=r'https://supplyone.ap1.covapp.io/#/ground/orderManagement',button=r'left',curson=r'center',times=1,run_mode=r'unctrl',waitfor=10)
        else:
            pass
      
    def flow7(self,detail=None,text=None):
        '''异常处理流程\n'''
        # 代码块
        self.__logger.debug('Flow:flow7,StepNodeTag:0211300351931,Note:发送失败邮件')
        import smtplib
        import datetime
        from PIL import ImageGrab
        from email.mime.text import MIMEText
        from email.header import Header
        from email.mime.multipart import MIMEMultipart
        import pandas as pd
        try:
            dfInitialize = pd.read_excel(self.configFile, sheet_name = 'Email')
            image_name = str(self.taskId) + "_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S") + ".png"
            image_path = self.imgPath + image_name
            # 截图整个屏幕, 保存到配置文件那里的地址, 文件名相同则覆盖
            image_plan = ImageGrab.grab()
            image_plan.save(image_path)
            mailserver =  dfInitialize['发送者邮箱服务器'].values.tolist()[0]
            port = dfInitialize['端口号'].values.tolist()[0]
            username_send = dfInitialize['发送者'].values.tolist()[0]
            password = dfInitialize['授权码'].values.tolist()[0]
            username_recv = dfInitialize['接收者'].values.tolist()[0]  # 收件人，多个收件人用逗号隔开
            env = dfInitialize['所属环境'].values.tolist()[0]  # 收件人，多个收件人用逗号隔开
            
            mail = MIMEMultipart()
            mail['Subject'] = '%s-网页下载相关流程失败' % env
            mail['From'] = username_send
            mail['To'] = username_recv
            message1 = MIMEText('taskId为%s' % str(self.taskId),'plain' ,'utf-8')
            mail.attach(message1)
            img_content = ""
            with open(image_path, "rb") as f:
                img_content = f.read()
            image_att = MIMEText(img_content, "base64", "utf-8")
            image_att["Content-Type"] = "application/octet-stream"
            image_att.add_header('Content-Disposition', 'attachment', filename=image_name)
            mail.attach(image_att)
            try:
                smtp = smtplib.SMTP(mailserver, port=port)
            except:
                smtp = smtplib.SMTP_SSL(mailserver, port=port)
            smtp.login(username_send, password)
            smtp.sendmail(username_send, username_recv.split(','), mail.as_string())
            smtp.quit()
            print('success')
        except Exception as e:
            print("邮件任务发送失败")
            print(str(e))
        
        # 代码块
        self.__logger.debug('Flow:flow7,StepNodeTag:0211305579934,Note:回调')
        # ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        #coding=utf-8
        import requests,json
        headers = {'Content-Type': 'application/json'}
        status = 1
        if self.TemplateCode == 'COMNW0040105':
            status = 0
        data = {
                "token":"a fox jumps over the lazy dog",
                "taskId": self.taskId,
                "templateCode": self.TemplateCode,
                "status": status,
                "originalUrl": self.originalUrl,
                "organizeUrl": self.organizeUrl,
                "message": text,
                "detail":text,                           # 和邮件报警内容保持一致，由传递的参数决定
                "data": ['']
        }
        s = requests.session()
        s.keep_alive = False
        res = requests.post(self.callbackUrl,data=json.dumps(data),headers = headers)
        print(res.text)   
            
        try:
            with open(self.taskDir+str(self.taskId)+'.txt','w',encoding='utf-8') as f:
                f.write(str(data))
        except:
            with open(self.taskDir+str(self.taskId)+'.txt','wb') as f:
                f.write(str(data))
        try:
            with open(self.robot_status,'w',encoding='utf-8') as f:
                f.write('1')
        except:
            with open(self.robot_status,'wb') as f:
                f.write('1')
            
            
        
        # 代码块
        self.__logger.debug('Flow:flow7,StepNodeTag:121018175512,Note:杀进程退出')
        import sys
        import os
        os.system("taskkill /im chrome.exe")
        os.system("taskkill /im iexplore.exe")
        sys.exit(-1)
      
    def test(self):
        # 代码块
        self.__logger.debug('Flow:test,StepNodeTag:26172415721259,Note:1')
        print(1/1)
        # 代码块
        self.__logger.debug('Flow:test,StepNodeTag:26172418353260,Note:2')
        print(1/0)
      
    def Main(self):
        re=None
        # Try异常
        self.__logger.debug('Flow:Main,StepNodeTag:171642064732,Note:设置主流程异常')
        try:
            # 代码块
            self.__logger.debug('Flow:Main,StepNodeTag:2709572107698,Note:初始化参数配置')
            import pandas as pd
            import os
            os.system("taskkill /im chrome.exe")
            # os.system(r'D:\RPA\RDP.bat')
            self.configFile = r'D:\RPA\configFile\configFile_saas.xlsx'
            dfInitialize = pd.read_excel(self.configFile, sheet_name = 'DServer')
            self.TemppathD = dfInitialize['ilink待结算模板文件'].values.tolist()[0]
            self.TemppathD_js = dfInitialize['ilink结算模板文件'].values.tolist()[0]
            self.ArrpathD = dfInitialize['ilink结算单本地整理后的文件存放文件夹'].values.tolist()[0]
            self.MovedirD = dfInitialize['ilink结算单本地下载的文件存放文件夹'].values.tolist()[0]
            self.downDir = dfInitialize['windows下载文件夹路径'].values.tolist()[0]
            print(self.downDir)
            self.Movedir1 = dfInitialize['通用下载存放文件夹'].values.tolist()[0]
            self.Arrpath1 = dfInitialize['通用整理后存放文件夹'].values.tolist()[0]
            self.Configdir = dfInitialize['临时文件夹'].values.tolist()[0]
            self.Temppath = dfInitialize['PO单通用字段模板'].values.tolist()[0]
            self.Arrpath = dfInitialize['ilink整理文件存放文件夹'].values.tolist()[0]
            self.Movedir = dfInitialize['ilink下载文件存放文件夹'].values.tolist()[0]
            self.Downdir = dfInitialize['windows下载文件夹路径'].values.tolist()[0]
            self.sftpDowndir = dfInitialize['通用sftp下载文件夹'].values.tolist()[0]
            dfInitialize1 = pd.read_excel(self.configFile, sheet_name = 'Common')
            self.taskDir = dfInitialize1['接口数据'].values.tolist()[0]
            self.robot_status = dfInitialize1['机器人状态文件'].values.tolist()[0]
            self.Txttob = dfInitialize1['接口数据文档'].values.tolist()[0]
            self.chromePath = dfInitialize1['chrome浏览器路径'].values.tolist()[0]
            self.imgPath = dfInitialize1['截图存储路径'].values.tolist()[0]
            print("获取sftp相关配置")
            df_initialize2 = pd.read_excel(self.configFile, sheet_name = 'SftpConfig')
            for idx, row in df_initialize2.iterrows():
                self.sftp_list.append([row['sftp主机IP'],row['sftp路径'],row['sftp账号'],row['sftp密码']])
                
                
                
            
            # 子流程:Parsing_Json
            self.__logger.debug('Flow:Main,StepNodeTag:0212450969522,Note:解析json')
            (temptemp)=self.Parsing_Json()
            # For循环
            self.__logger.debug('Flow:Main,StepNodeTag:1615240219221,Note:遍历userList')
            for master_data in self.userList:
                # 代码块
                self.__logger.debug('Flow:Main,StepNodeTag:1615240219220,Note:')
                self.UserName = master_data['username']
                self.PassWord = master_data['password']
                try:
                    self.configList = master_data['configList'][0]
                except:
                    print('没有主数据！')    
                    print('没有主数据！')    
                    print('没有主数据！')    
                #print(self.configList)
                try:
                    configl = []
                    configl.append(self.configList['dataFilter'])
                    print(configl)
                    self.Interface.append(self.configList['dimSales'])   
                    print('self.Interface',self.Interface)
                    print('self.Interface',self.Interface)
                    print('self.Interface',self.Interface)
                    print('self.Interface',self.Interface)
                except:
                    pass
                    print('无主数据！！')    
                    print('无主数据！！')    
                    print('无主数据！！')    
                    print('无主数据！！')    
                    print('无主数据！！')    
                configl = configl[0]
                self.Interface = self.Interface[0]
                #print(configl)    
                print(self.Interface)    
                # 序列
                self.__logger.debug('Flow:Main,StepNodeTag:1615454176344,Note:')
                # IF-N分支
                self.__logger.debug('Flow:Main,StepNodeTag:1615454176351,Note:判断是否为通用物流登录')
                if self.TemplateCode == 'COMNW0020102':
                    # 子流程:Login_ty
                    self.__logger.debug('Flow:Main,StepNodeTag:1615454176348,Note:通用物流登录流程')
                    (temptemp)=self.Login_ty()
                else:
                    pass
                # For循环
                self.__logger.debug('Flow:Main,StepNodeTag:1615240219219,Note:')
                for self.Datadic in configl:
                    # 序列
                    self.__logger.debug('Flow:Main,StepNodeTag:021245096959,Note:')
                    # IF-N分支
                    self.__logger.debug('Flow:Main,StepNodeTag:0212450969518,Note:')
                    if self.TemplateCode == 'COMNW0020102':
                        # 子流程:flow2
                        self.__logger.debug('Flow:Main,StepNodeTag:0212450969514,Note:通用物流')
                        (temptemp)=self.flow2()
                    else:
                        pass
                # 代码块
                self.__logger.debug('Flow:Main,StepNodeTag:1615551996481,Note:for循环configl任务完成')
                time.sleep(5)
                import os
                os.system("taskkill /im chrome.exe")
                time.sleep(2)
                # os.system("taskkill /im iexplore.exe")
                
            # 代码块
            self.__logger.debug('Flow:Main,StepNodeTag:3017063062363,Note:遍历结算，回调')
            # ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            #coding=utf-8
            import requests,json
            headers = {'Content-Type': 'application/json'}
            data = {
                    "token":"a fox jumps over the lazy dog",
                    "taskId": self.taskId,
                    "templateCode": self.TemplateCode,
                    "status": 0,
                    "originalUrl": self.originalUrl,
                    "organizeUrl": self.organizeUrl,
                    "message": "",
                    "detail":"",
                    "data": ['']
            }
            s = requests.session()
            s.keep_alive = False
            res = requests.post(self.callbackUrl,data=json.dumps(data),headers = headers)
            print(res.text)   
            try:
                with open(self.taskDir+str(self.taskId)+'.txt','w',encoding='utf-8') as f:
                    f.write(str(data))
            except:
                with open(self.taskDir+str(self.taskId)+'.txt','wb') as f:
                    f.write(str(data))
            try:
                with open(self.robot_status,'w',encoding='utf-8') as f:
                    f.write('1')
            except:
                with open(self.robot_status,'wb') as f:
                    f.write('1')
                
                
            
        except Exception as e:
            # 代码块
            self.__logger.debug('Flow:Main,StepNodeTag:301611577822,Note:打赢一场')
            print('打印异常',e)
            # 子流程:flow7
            self.__logger.debug('Flow:Main,StepNodeTag:171647142898,Note:进入异常流程处理')
            (temptemp)=self.flow7(detail=None,text='主流程异常')
        finally:
            # 代码块
            self.__logger.debug('Flow:Main,StepNodeTag:1716474227310,Note:关闭浏览器')
            import os
            os.system("taskkill /im chrome.exe")
            os.system("taskkill /im iexplore.exe")
 
if __name__ == '__main__':
    robot_no = ''
    proc_no = ''
    job_no = ''
    input_arg = ''
    try:
        argv = sys.argv[1:]
        opts, args = getopt.getopt(argv,"hr:p:j:i:",["robot = ","proc = ","job = ","input = "])
    except getopt.GetoptError:
        print ('robot.py -r <robot> -p <proc> -j <job>')
    for opt, arg in opts:
        if opt == '-h':
            print ('robot.py -r <robot> -p <proc> -j <job>')
        elif opt in ("-r", "--robot"):
            robot_no = arg
        elif opt in ("-p", "--proc"):
            proc_no = arg
        elif opt in ("-j", "--job"):
            job_no = arg
        elif opt in ("-i", "--input"):
            input_arg = arg
    pro = Dserver(robot_no=robot_no,proc_no=proc_no,job_no=job_no,input_arg=input_arg)
    pro.Main()
